<?php

namespace app\admin\controller;

use app\common\model\StudentFankui as FankuiModel;
use app\common\model\Student;
class Fankui extends Base
{
    /**
     * 列表
     * @return \think\response\Json
     */
    public function fankui_list()
    {
        if (request()->isPost()) {
            $data = input('');
            $page = input('page', 1);
            $size = input('size', 20);
            $where = [];
            if ($data['name']) {
                $where['name'] = ['like', "%{$data['name']}%"];
            }

            if(!$this->manager['is_super']){
                $where['mid'] = $this->manager['id'];
            }
            $list = FankuiModel::getPage($where, $page, $size, 'id desc');

            $total = FankuiModel::getCount($where);
            return returnJson(0, '', compact('page', 'size', 'list', 'total'));
        }
    }
    /**
     * 列表
     * @return \think\response\Json
     */
    public function weifankui()
    {
        if (request()->isPost()) {
            $data = input('');
            $page = input('page', 1);
            $size = input('size', 20);
            $where = [];
            if ($data['name']) {
                $where['name'] = ['like', "%{$data['name']}%"];
            }
            if($data['type']){
                if($data['type'] == 2){
                    $date = date('Y-m');
                }else{
                    $now_y = date('Y');
                    $now_m = date('m');
                    if($now_m==1){
                        $m = 12;
                        $y = $now_y-1;
                    }else{
                        $m = $now_m-1;
                        $y = $now_y;
                    }
                    $date = date('Y-m',strtotime("{$y}-{$m}-01"));
                }
                $not_sids = FankuiModel::getColumn(['date'=>['eq',$date]],'sid');
                $where['id'] = ['not in',$not_sids];
            }
            $list = Student::getAll($where,  'id desc','id,name' );

            $total = Student::getCount($where);
            return returnJson(0, '', compact('list', 'total'));
        }
    }

    public function del_fankui()
    {
        $id = input('id');
        $where = array(
            'id' => $id
        );
        if($id){
            FankuiModel::setDel($where);
            return returnJson(1, '删除成功');
        }
    }



}

